home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / ZSI / writer.pyo (.txt) < prev   
Python Compiled Bytecode  |  2008-10-13  |  5KB  |  172 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from ZSI import _copyright, _get_idstr, ZSI_SCHEMA_URI
  5. from ZSI import _backtrace, _stringtypes, _seqtypes
  6. from ZSI.wstools.Utility import MessageInterface, ElementProxy
  7. from ZSI.wstools.Namespaces import XMLNS, SOAP, SCHEMA
  8. from ZSI.wstools.c14n import Canonicalize
  9. import types
  10. _standard_ns = [
  11.     ('xml', XMLNS.XML),
  12.     ('xmlns', XMLNS.BASE)]
  13. _reserved_ns = {
  14.     'SOAP-ENV': SOAP.ENV,
  15.     'SOAP-ENC': SOAP.ENC,
  16.     'ZSI': ZSI_SCHEMA_URI,
  17.     'xsd': SCHEMA.BASE,
  18.     'xsi': SCHEMA.BASE + '-instance' }
  19.  
  20. class SoapWriter:
  21.     
  22.     def __init__(self, envelope = True, encodingStyle = None, header = True, nsdict = { }, outputclass = None, **kw):
  23.         if not outputclass:
  24.             pass
  25.         outputclass = ElementProxy
  26.         if not issubclass(outputclass, MessageInterface):
  27.             raise TypeError, 'outputclass must subclass MessageInterface'
  28.         
  29.         self.dom = outputclass(self)
  30.         self.memo = []
  31.         self.nsdict = nsdict
  32.         self.envelope = envelope
  33.         self.encodingStyle = encodingStyle
  34.         self.header = header
  35.         self.body = None
  36.         self.callbacks = []
  37.         self.closed = False
  38.  
  39.     
  40.     def __str__(self):
  41.         self.close()
  42.         return str(self.dom)
  43.  
  44.     
  45.     def getSOAPHeader(self):
  46.         if self.header in (True, False):
  47.             return None
  48.         
  49.         return self.header
  50.  
  51.     
  52.     def serialize_header(self, pyobj, typecode = None, **kw):
  53.         kw['unique'] = True
  54.         soap_env = _reserved_ns['SOAP-ENV']
  55.         header = self._header
  56.         if header is None:
  57.             header = self._header = self.dom.createAppendElement(soap_env, 'Header')
  58.         
  59.         typecode = getattr(pyobj, 'typecode', typecode)
  60.         if typecode is None:
  61.             raise RuntimeError('typecode is required to serialize pyobj in header')
  62.         
  63.         helt = typecode.serialize(header, self, pyobj, **kw)
  64.  
  65.     
  66.     def serialize(self, pyobj, typecode = None, root = None, header_pyobjs = (), **kw):
  67.         self.body = None
  68.         if self.envelope:
  69.             soap_env = _reserved_ns['SOAP-ENV']
  70.             self.dom.createDocument(soap_env, 'Envelope')
  71.             for prefix, nsuri in _reserved_ns.items():
  72.                 self.dom.setNamespaceAttribute(prefix, nsuri)
  73.             
  74.             self.writeNSdict(self.nsdict)
  75.             if self.encodingStyle:
  76.                 self.dom.setAttributeNS(soap_env, 'encodingStyle', self.encodingStyle)
  77.             
  78.             if self.header:
  79.                 self._header = self.dom.createAppendElement(soap_env, 'Header')
  80.                 for h in header_pyobjs:
  81.                     self.serialize_header(h, **kw)
  82.                 
  83.             
  84.             self.body = self.dom.createAppendElement(soap_env, 'Body')
  85.         else:
  86.             self.dom.createDocument(None, None)
  87.         if typecode is None:
  88.             typecode = pyobj.__class__.typecode
  89.         
  90.         if self.body is None:
  91.             elt = typecode.serialize(self.dom, self, pyobj, **kw)
  92.         else:
  93.             elt = typecode.serialize(self.body, self, pyobj, **kw)
  94.         if root is not None:
  95.             if root not in (0, 1):
  96.                 raise ValueError, 'SOAP-ENC root attribute not in [0,1]'
  97.             
  98.             elt.setAttributeNS(SOAP.ENC, 'root', root)
  99.         
  100.         return self
  101.  
  102.     
  103.     def writeNSdict(self, nsdict):
  104.         for k, v in nsdict.items():
  105.             if (k, v) in _standard_ns:
  106.                 continue
  107.             
  108.             rv = _reserved_ns.get(k)
  109.             if rv:
  110.                 if rv != v:
  111.                     raise KeyError('Reserved namespace ' + str((k, v)) + ' used')
  112.                     continue
  113.                 continue
  114.             
  115.             if k:
  116.                 self.dom.setNamespaceAttribute(k, v)
  117.                 continue
  118.             self.dom.setNamespaceAttribute('xmlns', v)
  119.         
  120.  
  121.     
  122.     def ReservedNS(self, prefix, uri):
  123.         return _reserved_ns.get(prefix, uri) != uri
  124.  
  125.     
  126.     def AddCallback(self, func, *arglist):
  127.         self.callbacks.append((func, arglist))
  128.  
  129.     
  130.     def Known(self, obj):
  131.         obj = _get_idstr(obj)
  132.         if obj in self.memo:
  133.             return 1
  134.         
  135.         self.memo.append(obj)
  136.         return 0
  137.  
  138.     
  139.     def Forget(self, obj):
  140.         obj = _get_idstr(obj)
  141.         
  142.         try:
  143.             self.memo.remove(obj)
  144.         except ValueError:
  145.             pass
  146.  
  147.  
  148.     
  149.     def Backtrace(self, elt):
  150.         return _backtrace(elt._getNode(), self.dom._getNode())
  151.  
  152.     
  153.     def close(self):
  154.         if self.closed:
  155.             return None
  156.         
  157.         for func, arglist in self.callbacks:
  158.             apply(func, arglist)
  159.         
  160.         self.closed = True
  161.  
  162.     
  163.     def __del__(self):
  164.         if not self.closed:
  165.             self.close()
  166.         
  167.  
  168.  
  169. if __name__ == '__main__':
  170.     print _copyright
  171.  
  172.